﻿using System;
using System.Web.Routing;

namespace Basmus.Values.Web
{
    internal static class RoutingHelper
    {
        public const string SchemeKeyDataTokenName = "routeKey";

        public static string GetRouteName(Type modelType, SchemeKey schemeKey)
        {
            return modelType.AssemblyQualifiedName + (schemeKey.IsDefault ? "/" : schemeKey.Key);
        }

        public static SchemeKey GetRouteKey(RouteData routeData)
        {
            var key = routeData.DataTokens.ContainsKey(SchemeKeyDataTokenName)
                          ? (SchemeKey)routeData.DataTokens[SchemeKeyDataTokenName]
                          : SchemeKey.Default;
            return key;
        }
    }
}
